﻿using System;
using System.Text;
using System.Globalization;

namespace HopNguyenCore.Extensions
{
    public class RemoveUnicode
    {
        public static string Remove(string s)
        {
            var stFormD = s.Normalize(NormalizationForm.FormD);
            var sb = new StringBuilder();
            foreach (var t in stFormD)
            {
                var uc = CharUnicodeInfo.GetUnicodeCategory(t);
                if(uc != UnicodeCategory.NonSpacingMark)
                {
                    sb.Append(t);
                }
            }
            var str = sb.ToString().Normalize(NormalizationForm.FormC);
            str = str.Replace(' ', '-');
            str = str.Replace('/', '-');
            str = str.Replace('\\', '-');
            str = str.Replace('&', '-');
            str = str.Replace('Đ', 'D');
            str = str.Replace('đ', 'd');
            str = str.Replace('+', '-');
            str = str.Replace('#', '-');
            str = str.Replace('~', '-');
            str = str.Replace('*', '-');
            str = str.Replace('(', '-');
            str = str.Replace(')', '-');
            str = str.Replace('[', '-');
            str = str.Replace(']', '-');
            str = str.Replace('{', '-');
            str = str.Replace('}', '-');
            str = str.Replace('|', '-');
            str = str.Replace('%', '-');
            str = str.Replace('$', '-');
            str = str.Replace('^', '-');
            str = str.Replace(';', '-');
            str = str.Replace('\'', '-');
            str = str.Replace('"', '-');
            str = str.Replace('<', '-');
            str = str.Replace('>', '-');
            str = str.Replace('?', '-');
            str = str.Replace(':', '-');
            str = str.Replace('.', '-');
            for(int i = 0; i < 20; i++)
                str = str.Replace("--", "-");
            return (str.ToLower());
        }
    }
}
